from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView

from tools.config import boss_job, new_city
from tools.tool import OCRToll


# Create your views here.
# class SendMainAPIView(APIView):
#     """发送邮件"""
#
#     def post(self, request):
#         sender = request.data.get('sender')
#         password = request.data.get('password')
#         receiver = request.data.get('receiver')
#         subject = request.data.get('subject')
#         message = request.data.get('message')
#         if not SendMail().send_email(sender, password, receiver, subject, message):
#             return Response({'status': 500, 'msg': '发送邮件失败'})
#         return Response({'status': 200, 'msg': '发送邮件成功'})


# class SearchAPIView(APIView):
#
#     def get(self, request):
#         rsp = {'status': 200, 'msg': '搜索成功'}
#         word = request.GET.get('word')
#         rsp['data'] = Search().baidu(word)
#         return Response(rsp)


# class BossAPiView(APIView):
#
#     def get(self, request):
#         rsp = {'status': 200, 'msg': '搜索成功'}
#         city = request.GET.get('city', False)
#         job = request.GET.get('job')
#         if job and '实习' not in job:
#             job = Word().get_word_job(job)
#             if city:
#                 city = Word().get_word_city(city)
#                 url = 'https://m.zhipin.com/salaryxc/' + f'c{city}_p{job}.html'
#                 content = Boss().salary(url)
#                 rsp['data'] = {'url': content}
#             else:
#                 url = 'https://m.zhipin.com/salaryxc/' + f'p{job}.html'
#                 content = Boss().salary(url)
#                 rsp['data'] = {'url': content}
#         else:
#             rsp = {'status': 500, 'msg': '搜索失败！', 'data': {'url': '无'}}
#         return Response(rsp)


# class BossSearchAPIView(APIView):
#
#     def get(self, request):
#         rsp = {'status': 200, 'msg': '搜索成功'}
#         city = request.GET.get('city')
#         job = request.GET.get('query', False)
#         if job:
#             city = Word().get_word_city(city)
#             if city:
#                 url = f'https://www.zhipin.com/web/geek/job?query={job}&city={city}'
#             else:
#                 url = f'https://www.zhipin.com/web/geek/job?query={job}'
#             content = Boss().search(url)
#             rsp['data'] = {'url': content}
#         else:
#             rsp = {'status': 500, 'msg': '无搜索内容'}
#         return Response(rsp)

class OCRAPIView(APIView):
    def post(self, request):
        rsp = {'status': 200, 'msg': 'ok','data': {}}
        url = request.data.get('url')
        rsp['data']['content'] = OCRToll().check_url_content(url)
        return Response(rsp)